package com.meixiang.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;

import com.meixiang.R;
import com.meixiang.activity.moments.ContentEditingActivity;
import com.meixiang.fragment.momentsContentFragment.FragmentSwitching;
import com.meixiang.global.apiConfig;
import com.meixiang.main.BaseFragment;
import com.meixiang.main.MainActivity;
import com.meixiang.tool.Tool;
import com.meixiang.view.TitleView;
import com.tencent.mm.sdk.openapi.IWXAPI;
import com.tencent.mm.sdk.openapi.WXAPIFactory;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * 社区
 * 作者：黑哥 on 2016/3/29 11:39
 */
public class MomentsFragment extends BaseFragment {
    @Bind(R.id.title)
    TitleView mTitle;
    private View view;
    private MainActivity activity;

    @Bind(R.id.moments_frame_content)
    FrameLayout mMomentsFrameContent;

    FrameLayout serviceFrameContent;
    FragmentManager manager;
    FragmentTransaction transaction;

    private IWXAPI api;


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        view = inflater.inflate(R.layout.fragment_moments, container, false);
        super.onCreateView(inflater, container, savedInstanceState);
        activity = (MainActivity) getActivity();
        api = WXAPIFactory.createWXAPI(activity, apiConfig.WX_APP_ID);
        api.registerApp(apiConfig.WX_APP_ID);
        ButterKnife.bind(this, view);
        return view;
    }

    @Override
    protected void initTitle() {


        mTitle.setTitle(getResources().getString(R.string.moments));
        mTitle.setRightImageButton(R.mipmap.fatie);
        mTitle.showRightButton(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (Tool.isFastDoubleClick()) return;
                startActivity(new Intent(activity, ContentEditingActivity.class));
            }
        });
    }

    @Override
    protected void initView() {
        manager = getChildFragmentManager();
        transaction = manager.beginTransaction();
        transaction.add(R.id.moments_frame_content, new FragmentSwitching());
        transaction.commit();

    }

    @Override
    protected void setData() {

    }


    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }
}
